from python_ai.common.xcommon import sep
import tensorflow as tf

c1 = tf.constant(9.5, dtype=tf.float32)
c2 = tf.constant(10, dtype=tf.int32)
print(c1)
print(c2)

a = tf.Variable(5.8)
b = tf.Variable(2.9)
print(a)
print(b)

sum = tf.Variable(0, name="sum")
result = tf.Variable(0, name="result")
print(sum)
print(result)

f = tf.Variable([[2., 5., 4.],
                 [1., 3., 6.]])

f2 = tf.Variable([[2., 3.],
                  [1., 2.],
                  [3., 1.]])
print(f)
print(f2)

sep('contant => multiply')
vector1 = tf.constant([3., 3.])  # 这里只有一对中括号 []，就是向量
vector2 = tf.constant([1., 2.])
result3 = tf.multiply(vector1, vector2)  # 向量乘法。tf.multiply()
result4 = tf.multiply(vector2, vector1)
print(vector1)
print(vector2)
print(result3)
print(result4)

sep('Run session')
sess = tf.Session()
sess.run(tf.global_variables_initializer())  # 初始化所有变量
r3 = sess.run(result3)
r4 = sess.run(result4)
print(r3, '\n', r4)

sess.close()  # Close session

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(tf.argmax(f, axis=1)))
